<!--
 * @Descripttion: 
 * @version: 
 * @Author: 尹伊
 * @Date: 2020-07-08 15:45:12
 * @LastEditors: 尹伊
 * @LastEditTime: 2020-07-10 15:52:00
-->
<template>
  <div class="tree-demo">
    <el-tree :data="data" :props="defaultProps" show-checkbox @node-click="handleNodeClick" @click='handleCheck'>
    </el-tree>
  </div>
</template>
<script>
  export default {
    name: 'treeDemo',
    data() {
      return {
        data: [{
          label: '一级 1',
          children: [{
            label: '二级 1-1',
            children: [{
              label: '三级 1-1-1'
            }]
          }]
        }, {
          label: '一级 2',
          children: [{
            label: '二级 2-1',
            children: [{
              label: '三级 2-1-1'
            }]
          }, {
            label: '二级 2-2',
            children: [{
              label: '三级 2-2-1'
            }]
          }]
        }, {
          label: '一级 3',
          children: [{
            label: '三级 2-2-1'
          }]
        }],
        defaultProps: {
          children: 'children',
          label: 'label'
        }
      };
    },
    mounted() {

    },
    methods: {
      handleCheck(cur, checkedInfo) {
        console.log(cur, '当前选中')
        console.log(checkedInfo, '选中的内容')
      },
      handleNodeClick(data) {
        console.log(data);
        this.$nextTick(() => {
          let ml = document.getElementsByClassName('el-tree-node__children')
          let md = document.getElementsByClassName('el-tree-node__content')
          console.log(ml, ml[0].style.paddingLeft, '获取所有类名')
          console.log(md)
          // for (let i = 0; i < ml.length; i++) {
          //   for (let j = 0; j < md.length; j++) {
          //     if (md[j].style.paddingLeft !== '0px') {
          //       ml[i].style.marginLeft = 14 * (i + 1) + 'px'
          //       ml[i].style.borderLeft = '1px dashed '
          //     } else {
          //       ml[i].style.marginLeft = 14 + 'px'
          //       ml[i].style.borderLeft = '1px dashed '
          //     }
          //   }
          // }


          // for (let j = 0; j < md.length; j++) {
          //   for (let i = 0; i < ml.length; i++) {
          //     if (md[j].style.paddingLeft !== '0px') {
          //       ml[i].style.marginLeft = 14 * (i + 1) + 'px'
          //       ml[i].style.borderLeft = '1px dashed '
          //     } else {
          //       ml[i].style.marginLeft = 14 + 'px'
          //       ml[i].style.borderLeft = '1px dashed '
          //     }
          //   }
          // }
          // for (let i = 0; i < md.length; i++) {
          //   if (md[i].style.paddingLeft !== '0px') {
          //     md[i].style.paddingLeft = '0px'
          //   }
          // }
        })
      }
    }
  }
</script>
<style lang='scss' scoped>
  .tree-demo {
    width: 500px;
    height: 100%;
    margin: 100px auto;
  }

  .tree-demo /deep/ .el-tree {
    background: #fff;
  }

  .tree-demo /deep/ .el-tree .el-tree-node__expand-icon.expanded {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }

  .tree-demo /deep/ .el-tree .el-icon-caret-right:before {
    background: url('../../assets/img/u673.png') no-repeat;
    content: '';
    display: block;
    width: 16px;
    height: 16px;
    background-size: 16px;
  }

  .tree-demo /deep/ .el-tree .el-tree-node__expand-icon.expanded.el-icon-caret-right:before {
    background: url('../../assets/img/u670.png') no-repeat;
    content: '';
    display: block;
    width: 16px;
    height: 16px;
    background-size: 16px;
  }

  .tree-demo /deep/ .el-tree-node__expand-icon.is-leaf::before {
    display: none;
  }

  .tree-demo /deep/ span.is-leaf.el-tree-node__expand-icon.el-icon-caret-right {
    width: 28px;
    height: 28px;
  }

  /* .el-tree-node.is-expanded>.el-tree-node__children {
    border-left: 1px solid #000;
  } */
</style>